/* Version 1.00: "Silk Purse" */

package {
	import flash.display.MovieClip;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.*;
	import flash.system.Capabilities;
	import flash.utils.ByteArray;
	import flash.utils.getTimer;
	
	public class m1 extends MovieClip {
		public static var debug:Debugger;				
		private static var console:Console;
		
		public static var SysClk:Clock = new Clock(1); /* set fastest possible clock */
		
		private function InitIO():void {			
			var xres:uint;
			var yres:uint;
			var dbgwidth:uint;
			/* Auto-select video resolution for testing */
			switch (flash.system.Capabilities.screenResolutionX) { /* only my machines so far */
				case 1024: xres = 800; yres = 600; dbgwidth = 100; break;
				case 1280: xres = 800; yres = 600; dbgwidth = 200; break;
				case 1600: xres = 1024; yres = 768; dbgwidth = 200; break;					
				case 1920: xres = 1024; yres = 768; dbgwidth = 500; break;
				default: xres = 800; yres = 600; dbgwidth = 200; break; /* video res. defaults */
			}
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			stage.stageFocusRect = false;
			stage.showDefaultContextMenu = false;
			//stage.frameRate = 1000;
			debug = new Debugger(xres+5, 0, dbgwidth, yres);
			console = new Console(xres, yres);
			stage.addChild(debug);
			stage.addChild(console);
		}

		public function m1():void {
			InitIO();
			RAM.InitRAM();
			CPU.init();
			/*****************/
			Test.initdebug();
			/*****************/
			
			Flow.Ord(function():void {
				Net.Snarf("lmfont.bin"); /* Eventually replace ROM with disk... */
			});
			
			Flow.Ord(function():void {
				debug.print("ROM Loaded: " + Net.buffer.length + " bytes.");
				RAM.bytes.writeBytes(Net.buffer);
				/*****************/
				Test.setup();
				/*****************/
				Flow.Next();
			});
			
		}
	}
}